package org.filetransfer.file_transfer_java_backend.controller;
import org.filetransfer.file_transfer_java_backend.entity.Message;
import org.filetransfer.file_transfer_java_backend.service.MessageService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import javax.swing.text.html.Option;
import java.util.List;
import java.util.Optional;
@RestController
@RequestMapping("/api/messages")
public class MessageController {
    @Autowired
    private MessageService messageService;
    //    @GetMapping("/shareitem/{shareItemId}")
//    public ResponseEntity<List<Message>> getMessagesByShareItemId(@PathVariable Long shareItemId) {
//        List<Message> messages = messageService.getMessagesByShareItemId(shareItemId);
//        if (messages.isEmpty()) {
//            return ResponseEntity.noContent().build();
//        }
//        return ResponseEntity.ok(messages);
//    }
//    @PostMapping
//    public ResponseEntity<Message> createMessage(@RequestBody Message message) {
//        Message createdMessage = messageService.createMessage(message);
//        return ResponseEntity.ok(createdMessage);
//    }
//    @GetMapping("/{id}")
//    public ResponseEntity<Message> getMessageById(@PathVariable Long id) {
//        Message message = messageService.getMessageById(id);
//        return ResponseEntity.ok(message);
//    }

    @PostMapping("/{code}/{token}/add")
    public Message addMessage(@PathVariable String code, @PathVariable String token, @RequestBody String message) {
        return messageService.addMessage(code, token, message);
    }
    public record AddMessageRequest(String message) {}
    @PostMapping("/{code}/{token}/add/v2")
    public Message addMessageV2(@PathVariable String code, @PathVariable String token, @RequestBody AddMessageRequest message) {
        return messageService.addMessage(code, token, message.message);
    }
    @DeleteMapping("/{code}/{token}/delete")
    public boolean deleteMessage(@PathVariable String code, @PathVariable String token, @RequestBody long msgId) {
        return messageService.deleteMessage(code, token, msgId);
    }
    @GetMapping("/{code}/get")
    public List<Message> getMessages(@PathVariable String code) {
        return messageService.getMessages(code);
    }
}